package forces;

import physicalobjects.Mass;

/**
 * This is the viscosity force.
 *
 * @author Kathleen Lan, Seon Kang
 */

public class Viscosity extends Force {

    private static final double DEFAULTSCALEFACTOR = 0.01;

 // either equal to DEFAULT_MAGNITUDE or
    // magnitude inputed from Environmental data
    // file
    private double myBaseScaleFactor;
 // current magnitude (equals 0 when
    // CenterOfMass is toggled off,
    private double myCurrentScaleFactor;
    private String myForceName = "viscosity";

    /**
     *
     */
    public Viscosity () {
        setMyName(myForceName);
        myCurrentScaleFactor = DEFAULTSCALEFACTOR;
        myBaseScaleFactor = DEFAULTSCALEFACTOR;
    }

    /**
     *
     * @param c 
     */
    public Viscosity (double c) {
        setMyName(myForceName);
        myCurrentScaleFactor = c;
        myBaseScaleFactor = c;
    }

    @Override
    public void toggleForce () {
        myCurrentScaleFactor = myBaseScaleFactor - myCurrentScaleFactor;
        System.out.println("Toggled! Viscosity: " + myCurrentScaleFactor);
    }

    // takes (most recent) velocity of the Mass and returns the corresponding
    // Viscosity force
    @Override
    public void update (Mass m) {
        Force massVelocity = m.getVelocity();
        setMagnitude(massVelocity.getMagnitude());
        setDirection(massVelocity.getDirection());
        negate();
        scale(myCurrentScaleFactor);
        m.applyForce(this);
    }
}
